<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="btnFetch" runat="server" Text="Fetch" OnClick="Fetch" /> <br /><br /> <asp:Label ID="Label1" runat="server"></asp:Label> </form> </body> </html>
Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Partial Class _Default Inherits System.Web.UI.Page Protected Sub Fetch(sender As Object, e As EventArgs) Dim conStr As String = "workstation id=ArtVault.mssql.somee.com;packet size=4096;user id=Aalleyy_SQLLogin_1;pwd=6hqepy6m5t;data source=ArtVault.mssql.somee.com;persist security info=False;initial catalog=ArtVault;TrustServerCertificate=True" Dim con As New SqlConnection(conStr) Dim cmd As New SqlCommand() cmd.Connection = con cmd.CommandText = "SELECT * FROM Person" Try con.Open() Dim dr As SqlDataReader = cmd.ExecuteReader() If dr.Read() Then Response.Write("Customer Name: " & dr("First_Name").ToString()) Else Response.Write("No data found.") End If dr.Close() Catch ex As Exception Label1.Text = ex.Message Finally con.Close() End Try End Sub End Class